package com.zenq.ssm.web.ctrl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageInfo;
import com.zenq.ssm.entity.Category;
import com.zenq.ssm.service.CategoryService;

@Controller
@RequestMapping("/c")
public class CategoryController {

	@Autowired
	private CategoryService categoryService;
	
	@RequestMapping("/page")
	public ModelAndView page(@ModelAttribute Category category,
			@RequestParam(required = false, defaultValue = "1" ) int page,
			@RequestParam(required = false, defaultValue = "10") int rows) {
		ModelAndView mav = new ModelAndView();
		List<Category> list = categoryService.getCategoryPage(category, page, rows);
		// 需要将数据传递到view视图上进行展示
		// request.setAttribute("key", Value);
		mav.addObject("pageInfo", new PageInfo<Category>(list));
		mav.addObject("queryParam", category);
		mav.addObject("page", page);
		mav.addObject("rows", rows);
		mav.setViewName("category/list");
		return mav;
	}
}
